package data;


public class DatedRating extends Rating {

	private String date;
	
	public DatedRating(short movieID, int userID, byte rating, String date) {
		super(movieID, userID, rating);
		this.date = date;
	}

	public DatedRating(short movieID, int userID, byte rating, short day, short month, short year) {
		super (movieID, userID, rating);
		String date = "" + twoDigit(day) + "-" + twoDigit(month);
		//2015 and under
		if (year < 15){
			date += "-20";
		}else{
			date += "-19";
		}
		date += twoDigit(year);
		this.date = date;
	}

	/**
	 * Returns a String of the passed short with at least two digits.
	 * Eg, 9 returns "09" and 14 returns "14".
	 * @param number
	 * @return
	 */
	private String twoDigit(short number) {
		if (number < 10){
			return "0" + number;
		}
		return "" + number;
	}

	public String getDate() {
		return date;
	}

	public short[] getDateAsShorts() {
		//{dd,mm,yy}
		short[] sDate = new short[3];
		//Date is initially in format: yyyy-mm-dd
		//System.out.println("{" + this.date + "}");
		//Day of month
		sDate[0] = Short.parseShort(date.substring(8,10));
		//Month of year
		sDate[1] = Short.parseShort(date.substring(5,7));
		//Year, as two digits only
		sDate[2] = Short.parseShort(date.substring(2,4));
		
		return sDate;
		
	}

	public static void main(String arg[]){
		String date = "2000-12-19";
		System.out.println("Date: " + date);
		DatedRating dr = new DatedRating((short)1,1,(byte)1,date);
		short[] sDate = dr.getDateAsShorts();
		
		for (short s: sDate){
			System.out.println("Short: " + s);
		}
	}
}
